package com.platform.sys.modular.syncdata.executor;

import cn.hutool.db.sql.SqlExecutor;
import cn.hutool.log.Log;
import com.platform.sys.modular.syncdata.executor.abs.SyncDataStrategy;
import com.platform.sys.modular.syncdata.param.SyncDataParam;
import com.platform.sys.modular.syncdata.result.TargetResult;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 递增策略
 */
public class IncreaseStrategyExecutor extends SyncDataStrategy {

    private static final Log log = Log.get();


    @Override
    public String getName() {
        return null;
    }

    @Override
    public Integer syncData(Connection conn, TargetResult result, SyncDataParam syncDataParam) throws SQLException {
        log.info("++++++++++++++++++同步递增数量++++++++++++++++++++++++++");
        int execute = 0;
        String update_sql = " update "+result.getTableName()+" set "+result.getFieldName()+" = "+result.getFieldName()+" + ? where "+result.getQueryField()+" = ?";
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++");
        System.out.println(update_sql);
        execute = SqlExecutor.execute(conn, update_sql, syncDataParam.getOperationFieldValue(), syncDataParam.getQueryFieldValue());
        return execute;
    }
}
